<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<link data-th-include="commons::res">
<link data-th-include="commons::ueditor">
<script type="text/javascript">
	layui.use([ 'form', 'layer', 'jquery' ], function() {
		let form = layui.form, layer = layui.layer, $ = layui.jquery;
		let ue = UE.getEditor('editor', {
			initialFrameHeight : 100,
			autoHeightEnabled : false,
			maximumWords : 200,
			toolbars : [ [ 'redo', //重做
			'bold', //加粗
			'italic', //斜体
			'underline', //下划线
			'strikethrough', //删除线
			'subscript', //下标
			'superscript', //上标
			'formatmatch', //格式刷
			'fontfamily', //字体
			'fontsize',//字号
			'forecolor', //字体颜色
			'backcolor', //背景色
			'spechars', //特殊字符
			'justifyleft', //居左对齐
			'justifyright', //居右对齐
			'justifycenter', //居中对齐
			'justifyjustify', //两端对齐  
			'paragraph', //段落格式
			'undo', //撤销
			'source', //源代码
			'blockquote', //引用
			'time', //时间
			'date', //日期
			'unlink', //取消链接
			'insertcode', //代码语言
			'link', //超链接
			'emotion' //表情
			] ]
		});

		form.on("submit(comment)", function(data) {
			console.log(data.field.content);
			layer.msg("提交成功");
			$.ajax({
				type : 'post',
				url : '[[@{/comment/add}]]',
				data : data.field,
				dataType : 'json',
				success : function(rs) {
					if (rs.code === 0) {
						parent.loadComment();
						var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
						parent.layer.msg(rs.msg);
						parent.layer.close(index);    
					} else {
						layer.msg(`${rs.msg}:${rs.error}`);
					}
				}
			});
			return false;
		})
	})
</script>
</head>
<body>
	<div class="layui-fluid">
		<form class="layui-form">
			<input type="hidden" name="articleId"
				data-th-value="${param.articleId?:articleId}"> <input
				type="hidden" name="pid" data-th-value="${param.pid?:pid}">
			<div class="layui-form-item">
				<script type="text/plain" name="content" id="editor"></script>
			</div>
			<div class="layui-form-item" style="text-align: center;">
				<a class="layui-btn layui-btn-normal" lay-submit
					lay-filter="comment">提交回复</a>
			</div>
		</form>
	</div>
</body>
</html>